import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class Exam_8 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("输入框和表单"),
      ),
      body: Content(),
    );
  }

}

class Content extends StatelessWidget{

  TextEditingController _unameController = TextEditingController();

  FocusNode _focusNode = new FocusNode();

  @override
  Widget build(BuildContext context) {

    //监听焦点变化
    _focusNode.addListener((){
      print(_focusNode.hasFocus);
    });

    // TODO: implement build
    return  Column(
      children: <Widget>[
        
        TextField(
          autofocus: true,
          focusNode: _focusNode,
          controller: _unameController,//设置Controller
          decoration: InputDecoration(
            labelText: "用户名",
            hintText: "用户名或邮箱",
            prefixIcon: Icon(Icons.person),
          ),
          onChanged: (value){ //每次变化就会回调，不是根据时间间隔来的
            print("onchange:$value");
          },

        ),

        TextField(
        autofocus: true,
          decoration: InputDecoration(
            labelText: "密码",
            hintText: "请输入登录密码",
            prefixIcon: Icon(Icons.lock),
          ),
          obscureText: true,
        ),

        RaisedButton(
          child: Text("点击"),
          onPressed: (){
           print(_unameController.text);
          },
        ),
      ],
    );
  }

}